package com.lcifn.spring.aop.bean;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class CglibBrowserProxy implements MethodInterceptor{
	
	private static CglibBrowserProxy proxy = new CglibBrowserProxy();
	
	private CglibBrowserProxy(){
		
	}
	
	public static CglibBrowserProxy getInstance(){
		return proxy;
	}

	public <T> T getProxy(Class<T> clazz){
		return (T) Enhancer.create(clazz, this);
	}
	
	public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
		encrypt();
		Object retVal = proxy.invokeSuper(obj, args);
		decrypt();
		return retVal;
	}
	
	/**
	 * 加密
	 */
	private void encrypt(){
		System.out.println("encrypt ...");
	}
	
	/**
	 * 解密
	 */
	private void decrypt(){
		System.out.println("decrypt ...");
	}
}
